var app = angular.module('myApp.directives', []);

//循环结束监听
app.directive('repeatFinish', ["$timeout", function ($timeout) {
    return {
        restrict: 'A',
        link: function (scope, element, attr) {
            if (scope.$last == true) {
                $timeout(function () {
                    scope.$eval(attr.repeatFinish);
                });
            }
        }
    }
}]);
// 阻止IOS键盘弹出
app.directive('stopKeyboard', [function () {
    return {
        restrict: 'A',
        scope: false,
        link: function (scope, element, attr) {
            element.on('focus', function () {
                this.blur();
            })
        }
    }
}]);
//公共tab
app.directive('myListTab', ["$compile", function ($compile) {
    return {
        restrict: 'E',
        template: '<ul class="my-flex"></ul>',
        replace: true,
        link: function (scope, element, attrs) {
            element.html(
                '<li class="my-fs-14 my-tac my-tab" ng-repeat="tab in '+ attrs.tabs + ' " ng-class="{\'active\': ' + attrs['active'] + '(tab)}" ng-click="' + attrs.click + '(tab, $index)">{{tab}}</li>'
            );
            element.addClass(attrs.css);
            element.replaceWith($compile(element[0].outerHTML)(scope));
        }
    }
}]);
//公共tab
app.directive('comTab', ["$compile", function ($compile) {
    return {
        restrict: 'E',
        template: '<div class="weui-flex my-tabs"></div>',
        replace: true,
        link: function (scope, element, attrs) {
            element.html(
                '<div class="weui-flex__item fs-0 my-item-wrapper" ng-repeat="tab in '
                + attrs.tabs
                + ' " ng-class="{\'active\': '
                + attrs['active']
                + '(tab)}" ng-click="'
                + attrs.click
                + '(tab, $index)"><div class="my-item fs-14">{{tab}}</div></div>'
            );
            element.addClass(attrs.css);
            element.replaceWith($compile(element[0].outerHTML)(scope));
        }
    }
}]);

